#

| Chapter 16 Where Did I Put That? |

## 16.12 Useful ls Aliases

Because ls is one of the most commonly used UNIX commands and provides numerous options, it's a good idea to create aliases for the display formats that best suit your needs. For example, many users always want to know about their "hidden" files. That's reasonable - they're just as important as any other files you have. In some cases, they can grow to take up lots of room (for example, some editors hide backup files), so it's worth being aware of them.

Rather than typing `ls -a` every time, you can create a convenient alias that supplies the -a or -A option (16.11) automatically:

>     alias la "ls -aF"

or:

>     alias la "ls -AF"

Two things to note here. First, I recommend using la as the name of the alias, rather than just renaming ls. I personally think it's dangerous to hide the pure, unadulterated command underneath an alias; it's better to pick a new name, and get used to using that name. If you ever need the original ls for some reason, you'll be able to get at it without problems.

Second, what's with the -F option? I just threw it in to see if you were paying attention. It's actually quite useful; many users add it to their ls aliases. The -F option shows you the type of file in each directory by printing an extra character after each filename. Table 16.1 lists what the extra character can be.

Table 16.1: Filename Types Listed by ls -F
Character | Definition
--- | ---
(nothing) | The file is a regular file.
* | The file is an executable.
/ | The file is a directory.
@ | The file is a symbolic link (18.4).
= | The file is a "socket" (don't worry about this).

For example:

>     % la   Alias includes -F functionality
>     .cshrc   .login        Mail/         performance/
>     .emacs   .mailrc       mail.txt      powertools@

This says that Mail and performance are directories. powertools is a symbolic link (ls -l will show you what it's linked to). There are no executables or "sockets" in this directory.

You may want this version instead:

>     alias la ls -aFC

The -C option lists the files in multiple columns. This option isn't needed on systems where multi-column output is the normal behavior (for example, in SVR4). Note, however, that when piped to another command, ls output is single-column unless -C is used. For example, use `ls -C | more` to preserve multiple columns.

Finally, if you often need the full listing, use the alias:

>     alias ll ls -l

This alias may not seem like much of a shortcut until after you've typed it a dozen times. In addition, it's easy to remember as "long listing." Some UNIX systems even include ll as a regular command.

- DG, ML

16.11 Showing Hidden Files with ls -A and -a |  | 16.13 Can't Access a File? Look for Spaces in the Name